home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / Install / program files / Borland / BDS / 3.0 / Demos / Delphi.Net / CLR / Shapes / Triangle.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2004-10-22  |  1.2 KB  |  46 lines

  1. unit Triangle;
  2. {*******************************************************************************
  3.   ShapesDemo
  4.   Written by David Clegg, davidclegg@optusnet.com.au.
  5.  
  6.   This unit contains the Triangle class used to render a triangle onto a GDI+
  7.   drawing surface.
  8. *******************************************************************************}
  9.  
  10. interface
  11.  
  12. uses
  13.   Shape, System.Drawing, System.Drawing.Drawing2D;
  14.  
  15. type
  16.  
  17.   /// <summary>
  18.   /// Class to draw a Triangle.
  19.   /// </summary>
  20.   TTriangle = class(TShape)
  21.   protected
  22.     function GetShape(pStartPoint, pEndPoint: Point): GraphicsPath; override;
  23.   end;
  24.  
  25. implementation
  26.  
  27. /// <summary>
  28. /// Create a GraphicsPath object representing the bounds for the triangle
  29. /// </summary>
  30. function TTriangle.GetShape(pStartPoint, pEndPoint: Point): GraphicsPath;
  31. var
  32.   lStartPoint: Point;
  33.   lBottomLeft: Point;
  34. begin
  35.   Result := GraphicsPath.Create;
  36.  
  37.   lStartPoint := Point.Create(pEndPoint.X - ((pEndPoint.X - pStartPoint.X) div 2), pStartPoint.Y);
  38.   lBottomLeft := Point.Create(pStartPoint.X, pEndPoint.Y);
  39.  
  40.   Result.AddLine(lStartPoint, pEndPoint);
  41.   Result.AddLine(pEndPoint, lBottomLeft);
  42.   Result.AddLine(lBottomLeft, lStartPoint);
  43. end;
  44.  
  45. end.
  46.